package model;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.TreeSet;

public class Dictionary extends TreeSet{

	
	/**
	 * Serial version
	 */
	private static final long serialVersionUID = 1L;

	public Dictionary() {
		super();
	}

	@SuppressWarnings("unchecked")
	public Dictionary(List<Word> lw) {
		super(lw);
	}
	
	@SuppressWarnings("unchecked")
	public Dictionary(String fileName) {
		super(readDictionary(fileName));
	}
	
	private static List<Word> readDictionary(String name)  {
		 List<Word> wordList=new ArrayList<Word>();
		 Word word=null;
		 
		 try{
			 Scanner sc = new Scanner(new File(name)).useDelimiter("[\\s,.?;!]");
		 
			 while (sc.hasNext()) {
				 String parseWord = sc.next();
				 String words[]=parseWord.split("[:]");
				 word=new Word(words[0],words[1]);
				 wordList.add(word);
				 
				 for(int i=2; i<words.length;i++ )
					 word.addSyllable(words[i]);
				 
			 }
		 }catch(FileNotFoundException e) {
			 
		 }
	      return wordList;
	}
	
}
